package com.ctgu.springboot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.ctgu.springboot.common.QueryPageParam;
import com.ctgu.springboot.entity.TraInfo;
import com.ctgu.springboot.entity.Word;
import com.ctgu.springboot.mapper.TraInfoMapper;
import com.ctgu.springboot.mapper.WordMapper;
import com.ctgu.springboot.service.WordService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author cs
 * @since 2023-07-06
 */
@Service
public class WordServiceImpl extends ServiceImpl<WordMapper, Word> implements WordService {
    @Resource
    private WordMapper wordMapper;

    @Override
    public IPage<Word> wordPage(QueryPageParam query) {

        Integer id = (Integer) query.getParam().get("word_id");
        Integer stuid = (Integer) query.getParam().get("stu_id");
        String content = (String) query.getParam().get("word_content");
        String time = (String) query.getParam().get("word_time");

        Page<Word> page = new Page<>();
        page.setCurrent(query.getPageNum());
        page.setSize(query.getPageSize());

        LambdaQueryWrapper<Word> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        if (id!=null) {
            lambdaQueryWrapper.like(Word::getWordId, id);
        }
        if (id!=null) {
            lambdaQueryWrapper.like(Word::getStuId, stuid);
        }
        if (StringUtils.isNotBlank(content) && !"null".equals(content)) {
            lambdaQueryWrapper.like(Word::getWordContent, content);
        }
        if (StringUtils.isNotBlank(time) && !"null".equals(time)) {
            lambdaQueryWrapper.eq(Word::getWordTime, time);
        }
        return wordMapper.wordPage(page, lambdaQueryWrapper);
    }


    @Override
    public IPage<Word> teacherwordPage(QueryPageParam query) {

        Integer id = (Integer) query.getParam().get("word_id");
        Integer stuid = (Integer) query.getParam().get("stu_id");
        String content = (String) query.getParam().get("word_content");
        String time = (String) query.getParam().get("word_time");

        Page<Word> page = new Page<>();
        page.setCurrent(query.getPageNum());
        page.setSize(query.getPageSize());

        LambdaQueryWrapper<Word> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        if (id!=null) {
            lambdaQueryWrapper.like(Word::getWordId, id);
        }
        if (id!=null) {
            lambdaQueryWrapper.like(Word::getStuId, stuid);
        }
        if (StringUtils.isNotBlank(content) && !"null".equals(content)) {
            lambdaQueryWrapper.like(Word::getWordContent, content);
        }
        if (StringUtils.isNotBlank(time) && !"null".equals(time)) {
            lambdaQueryWrapper.eq(Word::getWordTime, time);
        }

        return wordMapper.teacherwordPage(page, lambdaQueryWrapper);
    }

    @Override
    public List<Word> getList(){
        return wordMapper.getList();
    }
}
